﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using DAL;

namespace FCTC_Web.Utilities
{
    public class DrapDownListHelper
    {
        public static SelectList InitialSelectionDropDownList<T>(string id, string field, string titleText, int? itemId = null) where T : class
        {
            var item = CH.GetDataById<T>(itemId);
            if (item != null)
            {
                var value = item.GetType().GetProperty(id).GetValue(item, null);
                return new SelectList(CH.GetAllData<T>(), field, titleText, value);
            }
            else
                return new SelectList(CH.GetAllData<T>(), field, titleText, itemId);
        }
    }
}